Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Valid Sudoku (medium)
Problem Statement
Determine if a 9x9 Sudoku board is valid. A valid Sudoku board will hold the following conditions:
- Each row must contain the digits 1-9 without repetition.
- Each column must contain the digits 1-9 without repetition.
- The 9 3x3 sub-boxes of the grid must also contain the digits 1-9 without repetition.
Note:
- The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
- You need to validate only filled cells.
Example 1:
- Input:
[["5","3",".",".","7",".",".",".","."] ,["6",".",".","1","9","5",".",".","."] ,[".","9","8",".",".",".",".","6","."] ,["8",".",".",".","6",".",".",".","3"] ,["4",".",".","8",".","3",".",".","1"] ,["7",".",".",".","2",".",".",".","6"] ,[".","6",".",".",".",".","2","8","."] ,[".",".",".","4","1","9",".",".","5"] ,[".",".",".",".","8",".",".","7","9"]] - Expected Output:
true - Justification: This Sudoku board is valid as it adheres to the rules of no repetition in each row, each column, and each 3x3 sub-box.
Example 2:
- Input:
[["8","3",".",".","7",".",".",".","."] ,["6",".",".","1","9","5",".",".","."] ,[".","9","8",".",".",".",".","6","."] ,["8",".",".",".","6",".",".",".","3"] ,["4",".",".","8",".","3",".",".","1"] ,["7",".",".",".","2",".",".",".","6"] ,[".","6",".",".",".",".","2","8","."] ,[".",".",".","4","1","9",".",".","5"] ,[".",".",".",".","8",".",".","7","9"]] - Expected Output:
false - Justification: The first and fourth rows both contain the number '8', violating the Sudoku rules.
Example 3:
- Input:
[[".",".","4",".",".",".","6","3","."] ,[".",".",".",".",".",".",".",".","."] ,["5",".",".",".",".",".",".","9","."] ,[".",".",".","5","6",".",".",".","."] ,["4",".","3",".",".",".",".",".","1"] ,[".",".",".","7",".",".",".",".","."] ,[".",".",".","5",".",".",".",".","."] ,[".",".",".",".",".",".",".",".","."] ,[".",".",".",".",".",".",".",".","."]] - Expected Output:
false - Justification: The fourth column contains the number '5' two times, violating the Sudoku rules.
Constraints:
board.length == 9board[i].length == 9board[i][j]is a digit 1-9 or '.'.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Sum of Subarray Minimums
Solution: Valid Sudoku
Mark as Completed
On this page
Problem Statement
Example 1:
Example 2:
Example 3:
Try it yourself